package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.entity.RegionEntity;
import com.cloudfun.campusshare.service.RegionService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("v1/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "provinceCode", value = "省编码", required = false, dataType = "String"),
            @ApiImplicitParam(name = "cityCode", value = "市编码", required = false, dataType = "String"),
    })
    @GetMapping
    public BaseResult<List<RegionEntity>> region(String provinceCode, String cityCode) {
        return BaseResultFactory.produceSuccess(regionService.getRegion(provinceCode, cityCode));
    }
}
